package framework.view.components.container.navigation
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.geom.Rectangle;

import framework.view.components.container.Repeater;

/**
 * VeriticalNavigator
 * @author jliang
 * 
 */	
public class VeriticalNavigator extends NavigatorBase
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function VeriticalNavigator()
	{
		super();
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	protected var prevBtn:Sprite;
	protected var nextBtn:Sprite;
	
	protected var movePoint:Point;
	
	public var step:Number = 25;
	//==========================================================================
	//  Overridden methods: NavigatorBase
	//==========================================================================
	override protected function init():void
	{
		prevBtn = new Sprite();
		prevBtn.graphics.beginFill(0x000000, 1);
		prevBtn.graphics.drawRect(0, 0, 20, 20);
		prevBtn.graphics.endFill();		
		prevBtn.buttonMode = true;
		
		nextBtn = new Sprite();
		nextBtn.graphics.beginFill(0x000000, 1);
		nextBtn.graphics.drawRect(0, 0, 20, 20);
		nextBtn.graphics.endFill();		
		nextBtn.buttonMode = true;
		
		addChild(prevBtn);
		addChild(nextBtn);
	}
	
	override protected function initListener():void
	{
		prevBtn.addEventListener(MouseEvent.CLICK, clickPrevHandler);
		nextBtn.addEventListener(MouseEvent.CLICK, clickNextHandler);
	}
	
	override protected function clearListener():void
	{
		prevBtn.removeEventListener(MouseEvent.CLICK, clickPrevHandler);
		nextBtn.removeEventListener(MouseEvent.CLICK, clickNextHandler);
	}
	
	override protected function createContainerMask():void
	{
		super.createContainerMask();
		movePoint = this.startPoint.clone();
	}
	
	override protected function reset():void
	{
		movePoint = this.startPoint.clone();
	}
	
	override public function commitProperty():void
	{
		super.commitProperty();
		
		prevBtn.x = (rectWidth - prevBtn.width) / 2;
		prevBtn.y = 0;
		
		nextBtn.x = prevBtn.x;
		nextBtn.y = prevBtn.height + rectHeight + 20;
	}
	
	protected function clickPrevHandler(event:Event):void
	{
		if (movePoint.y >= startPoint.y) return;
		movePoint.y += step;
		moveTarget(movePoint.x, movePoint.y);
	}
	
	protected function clickNextHandler(event:Event):void
	{
		if (movePoint.y <= startPoint.y - (target.height - containerMask.height)) return;
		movePoint.y -= step;
		moveTarget(movePoint.x, movePoint.y);
	}
}
}




